/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bgate.object;

import com.bgate.core.Debug;
import com.bgate.screen.GameScreen;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author ChrisMorian
 */
public class LiuKang extends Character {
//    =========================  Image====================

    public static Image Iforward;
    public static Image Irun;
    public static Image Iidle;
    public static Image Idown;
    public static Image Ijump_lr;
    public static Image Ikick;
    public static Image Ikick_down;
    public static Image Ipunch;
    public static Image Irepeated_punch;
    public static Image Idown_punch;
    public static Image Ijump_fight;
    public static Image Iskill1;
    public static Image Iskill2;
    public static Image ImainSkill;
    public static Image IbeFall;
    public static Image IbePunch;
    public static Image IbePunch2;
    public static Image Iwrestle;
    public static Image IbeWrestle;
    public static Image InearFight;
    public static Image bien;
    public static Image chao1;
    public static Image chao2;
    public static Image Ibabality;

    public LiuKang(GameScreen gm, Character rival) {
        super(gm, rival);
        this.setPosition((gm.map.getWidth() - gm.getWidth()) / 2, backY);
        init();
    }

    public LiuKang(int level, GameScreen gm) {
        super(level, gm);
        this.setPosition((gm.map.getWidth() / 2) + 100, backY);
//        this.setPosition((gm.map.getWidth () + gm.getWidth()) / 2, backY);
        init();

    }

    public void init() {
        //================= Sequence frame
        idle = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
        forward = new int[]{0, 1, 2, 3, 4, 5, 6};
        backward = new int[]{6, 5, 4, 3, 2, 1, 0};
        run = new int[]{0, 1, 2, 3, 4, 5};
        sit = new int[]{1, 0};
        jump = new int[]{0, 10};
        punch = new int[]{0, 1, 2, 3};
        double_punch = new int[]{1, 2, 3, 4, 5, 4};
        kick_down = new int[]{0, 1, 1, 2, 2, 3, 4, 4, 5, 5, 6};
        kick = new int[]{0, 1, 1, 2, 2, 3, 4, 4};
        down_punch = new int[]{0, 1, 2, 3, 3, 4};
        jumpBack = new int[]{7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0};
        jumpFor = new int[]{1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 0};
        jumpFight = new int[]{0, 1};
        skill1 = new int[]{4, 5, 5, 5, 5, 5, 0, 1, 1, 1, 1};
        skill2 = new int[]{0, 1};
        bePunch = new int[]{0, 1, 1, 0, 0};
        beFall = new int[]{0, 1, 2, 3, 4, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10};
        wrestle = new int[]{0, 0, 1, 1, 2, 3, 3, 4, 5, 5, 5,};
        beWrestle = new int[]{0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10};
        nearFight = new int[]{0, 0, 4, 4, 6, 6, 6, 4, 4, 4, 4, 6, 6, 4, 4, 4, 2, 2, 5, 5, 5, 5, 5, 4, 4};
        highKick = new int[]{0, 0, 2, 2, 4, 4, 6, 6, 7, 7, 7, 4, 4};
        fatality1 = new int[]{0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 0, 1, 2, 3, 4};
        fatality2 = new int[]{};
        fatality3 = new int[]{};

        hitPunch = new int[]{2, 5};
        hitKickDown = new int[]{5};
        hitDown_Punch = new int[]{1, 2};
        hitKick = new int[]{7};
        nearFightHit = new int[]{4, 11, 18};
        hitHighKick = new int[]{8};

        // ================Image=================
        Iforward = Asset.loadImage("liukang/forward.png");
        Irun = Asset.loadImage("liukang/run.png");
        Iidle = Asset.loadImage("liukang/idle.png");
        Idown = Asset.loadImage("liukang/down.png");
        Ijump_lr = Asset.loadImage("liukang/jump_lr.png");
        Ikick = Asset.loadImage("liukang/kick.png");
        Ipunch = Asset.loadImage("liukang/punch.png");
        Ikick_down = Asset.loadImage("liukang/kick_down.png");
        Idown_punch = Asset.loadImage("liukang/down_punch.png");
        Ijump_fight = Asset.loadImage("liukang/jump_fight.png");
        Iskill1 = Asset.loadImage("liukang/skill1.png");
        Iskill2 = Asset.loadImage("liukang/skill2.png");
        ImainSkill = Asset.loadImage("liukang/mainSkill.png");
        IbePunch = Asset.loadImage("liukang/bePunch.png");
        IbeFall = Asset.loadImage("liukang/beFall.png");
//        IbePunch2 = Asset.loadImage("liukang/bePunch2.png");
        Iwrestle = Asset.loadImage("liukang/wrestle.png");
        IbeWrestle = Asset.loadImage("liukang/beWrestle.png");
        InearFight = Asset.loadImage("liukang/nearFight.png");
        chao1 = Asset.loadImage("liukang/chao1.png");
        chao2 = Asset.loadImage("liukang/chao2.png");
        bien = Asset.loadImage("liukang/bien.png");

    }

    public void present(Graphics g) {
    }
    // cycle 1;

    public void died() {
        if (this.count == -1) {
        } else {
        }
    }

    public void idle() {
        Debug.d("Liu Kang idle");
        col = true;
        if (count == -1) {
            this.setImage(Iidle, 64, 128);
            this.setFrameSequence(idle);
            count = 2;
        } else if (count++ >= 1) {
            count = 0;
            this.nextFrame();
        }
    }
    //cycle 1;

    public void backWard() {
//        Debug.d("Liu Kang backward");
        if (count == -1) {
            this.setImage(Iforward, 64, 128);
            if (left) {
                this.setVer(-5, 0);
            } else {
                this.setVer(5, 0);
            }

            this.setPosition(this.getX() - 1, this.getY() + dy);
            this.setFrameSequence(backward);
            count = 5;
        } else if (count++ >= 5) {
            count = 0;
            this.nextFrame();
            this.setPosition(this.getX() + dx, this.getY() + dy);
        }
    }
    //cycle 1;

    public void forWard() {
        Debug.d("Liu Kang forward");
        if (count == -1) {
            this.setImage(Iforward, 64, 128);
            if (!left) {
                this.setVer(-5, 0);
            } else {
                this.setVer(5, 0);
            }
            this.setPosition(this.getX() + 1, this.getY() + dy);
            this.setFrameSequence(forward);
            count = 5;
        } else if (count++ >= 5) {
            count = 0;
            this.nextFrame();
            this.setPosition(this.getX() + dx, this.getY() + dy);
        }
    }

    public void jump() {
//        Debug.d("Liu Kang jump");
//        Debug.d("Frame " + this.getFrame());
        if (count == -1) {
            this.setImage(Iidle, 64, 128);
            this.setFrameSequence(jump);
            count = 1;
            this.setVer(0, -29);
            this.setPosition(this.getX(), this.getY() + dy);
        } else {
            count++;
            if (count > 4) {
                if (this.getFrame() != 1) {
                    this.nextFrame();
                }
                count = 0;
            }
            this.setPosition(this.getX(), this.getY() + dy);
            if (this.getY() > this.backY) {
                this.setPosition(this.getX(), this.backY);
                this.setVer(0, 0);
                this.setState(Character.IDLE);
            }
        }
    }

    public void jump_back() {
//        Debug.d("Liu Kang jump back");
        if (count == -1) {
            this.setImage(Ijump_lr, 64, 128);
            this.setFrameSequence(jumpBack);
            this.setFrame(7);
            count = 3;
            this.setVer(-4, -32);
//            this.backY = this.getY();
            this.setPosition(this.getX(), this.getY() + dy);
        } else {
            if (this.getY() < (backY - 70)) {
                this.nextFrame();
                if (this.getFrame() == (jumpBack.length - 1)) {
                    this.nextFrame();
                }
//                this.setVer(dx, dy += 3);
                this.setPosition(this.getX() + dx, this.getY() + dy);

            } else {
                if (this.dy > 0) {
                    this.setFrame(jumpBack.length - 1);
                }
                this.setVer(dx - 1, dy);
                this.setPosition(this.getX() + dx, this.getY() + dy);
                if (this.getY() >= backY) {
                    this.setVer(0, 0);
                    this.setPosition(this.getX(), this.backY);
                    this.setState(Character.IDLE);
                }
            }
        }
    }

    public void jump_for() {
//        Debug.d("Liu Kang jump forward");
        if (count == -1) {
            this.setImage(Ijump_lr, 64, 128);
            this.setFrameSequence(jumpFor);
            this.setFrame(7);
            count = 3;
            this.setVer(4, -32);
//            this.backY = this.getY();
            this.setPosition(this.getX(), this.getY() + dy);
        } else {
            if (this.getY() < (backY - 70)) {
                this.nextFrame();
                if (this.getFrame() == (jumpFor.length - 1)) {
                    this.nextFrame();
                }
                this.setVer(dx, dy);
                this.setPosition(this.getX() + dx, this.getY() + dy);

            } else {
                this.setFrame(7);
                if (this.dy > 0) {
                    this.setFrame(jumpFor.length - 1);
                }
                this.setVer(dx + 1, dy);
                this.setPosition(this.getX() + dx, this.getY() + dy);
                if (this.getY() >= backY) {
                    this.setVer(0, 0);
                    this.setPosition(this.getX(), this.backY);
                    this.setState(Character.IDLE);
                }
            }
        }
    }

    public void jump_fight() {
        Debug.d("Liu kang Jump Fight");
        if (count == -1) {
            Debug.d("jump block 1");
            this.setImage(Ijump_fight, 64, 128);
            this.setFrameSequence(jumpFight);
            this.nextFrame();
            this.setPosition(this.getX(), this.getY() + dy);
            count = 4;
        } else {
            Debug.d("jump block 2");
            count++;
            Debug.d(dx + "========= " + dy);
            if (count > 4) {
                if (this.getFrame() != 1) {
                    this.nextFrame();
                }
                count = 0;
            }
            this.setPosition(this.getX(), this.getY() + dy);
            if (this.getY() > this.backY) {
                Debug.d("==========================jump block 2.1");
                this.setPosition(this.getX(), this.backY);
                this.setVer(0, 0);
                this.setState(Character.IDLE);
            } else if (this.getY() > (this.backY - 40)) {
                this.setImage(Iidle, 64, 128);
                Debug.d("jump block 2.2" + dx + " " + dy);
            }
            if (this.collidesWith(this.rival, true) && col) {
                if (rival.state != BACKWARD) {
                    rival.setState(Character.BEFALL2);
                    // tru mau
                }
                col = false;
            }
        }
    }

    public void jump_back_fight() {
//        Debug.d("Liu Kang jump back fight");
        if (count == -1) {
            this.setImage(Ijump_fight, 64, 128);
            this.setFrameSequence(jumpFight);
            this.nextFrame();
            this.setVer(dx, dy += 3);
            this.setPosition(this.getX() + dx, this.getY() + dy);
            count = 4;
        } else {
            if (this.getY() < (backY - 32)) {
                this.setVer(dx, dy);
                this.setPosition(this.getX() + dx, this.getY() + dy);
            } else {
                this.setImage(Iidle, 64, 128);
                this.setVer(dx - 1, dy += 4);
                this.setPosition(this.getX() + dx, this.getY() + dy);
                if (this.getY() >= backY) {
                    this.setPosition(this.getX() - dx, this.backY);
                    this.setVer(0, 0);
                    this.setState(Character.IDLE);
                }
            }
            if (this.collidesWith(this.rival, true) && col) {
                if (rival.state != BACKWARD) {
                    rival.setState(Character.BEFALL2);
                    //tru mau
                }
                col = false;
            }
        }
    }

    public void jump_for_fight() {
        if (count == -1) {
            this.setImage(Ijump_fight, 64, 128);
            this.setFrameSequence(jumpFight);
            this.nextFrame();
            this.setVer(dx, dy += 3);
            this.setPosition(this.getX() + dx, this.getY() + dy);
            count = 4;
        } else {
            if (this.getY() < (backY - 32)) {
                this.setVer(dx, dy);
                this.setPosition(this.getX() + dx, this.getY() + dy);
            } else {
                this.setImage(Iidle, 64, 128);
                this.setVer(dx + 1, dy);
                this.setPosition(this.getX() + dx, this.getY() + dy);
                if (this.getY() >= backY) {
                    this.setPosition(this.getX() - dx, this.backY);
                    this.setVer(0, 0);
                    this.setState(Character.IDLE);
                }
            }
            if (this.collidesWith(this.rival, true) && col) {
                if (rival.state != BACKWARD) {
                    rival.setState(Character.BEFALL2);
                    //tru mau
                }
                col = false;
            }
        }
    }

    public void sit() {
//        Debug.d("Liu Kang sit");
//        Debug.d("" + this.getFrame());
        if (count == -1) {
            this.setImage(Idown, 90, 128);
            this.setVer(0, 0);
            this.setFrameSequence(sit);
            count = 3;
        } else if (count++ >= 2 && this.getFrame() == 0) {
            count = 0;
            this.nextFrame();
        }
    }

    public void run() {
//        Debug.d("Liu Kang run");
        if (count == -1) {
            this.setImage(Irun, 64, 128);
            if (left) {
                this.setVer(10, 0);
            } else {
                this.setVer(-10, 0);
            }
            this.setPosition(this.getX() + 1, this.getY() + dy);
            this.setFrameSequence(run);
            count = 3;
        } else if (count++ >= 2) {
            count = 0;
            this.nextFrame();
            this.setPosition(this.getX() + dx, this.getY() + dy);
        }
    }

    public void punch() {
//        Debug.d("Liu Kang punch");
        if (count == -1) {
            this.setImage(Ipunch, 90, 128);
            this.setFrameSequence(punch);
            count = 3;
        } else if (count++ >= 2) {
            count = 0;
            if (this.getFrame() == 3) {
                this.state = Character.IDLE;
                this.count = -1;
            } else {
                this.nextFrame();
                this.testPunch = this.getFrame();
            }
            if (inHit(punch[this.getFrame()], hitPunch) && this.collidesWith(this.rival, true)) {
                if (rival.state != BACKWARD) {
                    rival.setState(Character.BEPUNCH);
                }

            }
        }
    }

    public void repeatedPunch() {
//        Debug.d("Liu Kang repeated punch");
        if (count == -1) {
            this.setFrameSequence(double_punch);
            for (int i = 0; i < testPunch; i++) {
                this.nextFrame();
            }
            count = 3;
        } else if (count++ >= 2) {
            count = 0;
            if (this.getFrame() == 4) {
                if (repeat) {
                    nextFrame();
                    repeat = false;
                } else {
                    this.count = -1;
                    this.state = Character.IDLE;
                }
            } else {
                nextFrame();
            }
            if (inHit(double_punch[this.getFrame()], hitPunch) && this.collidesWith(this.rival, true)) {
                if (rival.state != BACKWARD) {
                    rival.setState(Character.BEPUNCH);
                }

            }
        }
    }

    public void kick() {
//        Debug.d("Liu Kang kick");
        if (count == -1) {
            this.setImage(Ikick, 90, 128);
            this.setFrameSequence(kick);
            count = 3;
        } else if (true) {
            count = 0;
            if (this.getFrame() == (kick.length - 1)) {
                this.state = Character.IDLE;
                this.count = -1;
            } else {
                this.nextFrame();
            }
        }
        if (inHit(this.getFrame(), hitKick) && this.collidesWith(this.rival, true)) {
            if (rival.state != BACKWARD) {
                rival.setState(Character.BEPUNCH);
            }
        }
    }

    public void kickDown() {
//        Debug.d("Liu Kang kick down");
        if (count == -1) {
            this.setImage(Ikick_down, 90, 128);
            this.setFrameSequence(kick_down);
            count = 3;
        } else {
            count = 0;
            if (this.getFrame() == (kick_down.length - 1)) {
                this.state = Character.IDLE;
                this.count = -1;
            } else {
                this.nextFrame();
            }
            if (this.collidesWith(this.rival, true)
                    && this.inHit(this.getFrame(), hitKickDown)) {
                this.rival.setState(Character.BEFALL2);
            }
        }
    }

    public void nearly_fight() {
//        Debug.d("Liu Kang nearly fight 1");
        if (count == -1) {
            this.setImage(InearFight, 90, 128);
            this.setFrameSequence(nearFight);
            count = 0;
        } else {
            this.nextFrame();
            if (this.getFrame() == (nearFight.length - 1)) {
                this.setState(Character.IDLE);
            }
            if (inHit(this.getFrame(), nearFightHit) && this.collidesWith(this.rival, true)) {
                if (this.getFrame() == 18) {
                    rival.setState(Character.BEFALL2);
                } else {
                    rival.setState(Character.BEPUNCH);
                }
            }
        }
    }

    public void highKick() {
        if (count == -1) {
            this.setImage(InearFight, 90, 128);
            this.setFrameSequence(highKick);
            count = 0;
        } else {
            this.nextFrame();
            if (this.getFrame() == (highKick.length - 1)) {
                this.setState(Character.IDLE);
            }
            if (inHit(this.getFrame(), hitHighKick) && this.collidesWith(this.rival, true)) {
                rival.setState(Character.BEPUNCH);
            }
        }
    }

    public void punch_down() {
//        Debug.d("Liu Kang kick down");
        if (count == -1) {
            this.setImage(Idown_punch, 90, 128);
            this.setFrameSequence(down_punch);
            count = 3;
        } else if (true) {
            count = 0;
            if (this.getFrame() == (down_punch.length - 1)) {
                this.state = Character.IDLE;
                this.count = -1;
            } else {
                this.nextFrame();
            }
            if (this.collidesWith(this.rival, true)
                    && this.inHit(this.getFrame(), hitDown_Punch)) {
                this.rival.setState(Character.BEFALL1);
            }
        }
    }

    public void skill1() {
        Debug.d("Liu Kang skill 1");
        // skill 1 when jump
        if (count == -1) {
            this.setImage(Iskill1, 90, 128);
            this.setFrameSequence(skill1);
            this.setVer(0, 0);
            if (this.getY() == this.backY) {
                this.setFrame(6);
                if (left) {
                    gm.listSkill.addElement(new LiuKangSkill(this.getX(), this.getY(), 10));
                } else {
                    gm.listSkill.addElement(new LiuKangSkill(this.getX() - 13, this.getY(), -10));
                }

            } else {
                if (left) {
                    gm.listSkill.addElement(new LiuKangSkill(this.getX() + 35, this.getY(), 10));
                } else {
                    gm.listSkill.addElement(new LiuKangSkill(this.getX() - 45, this.getY(), -10));
                }
            }
            count = 1;
        } else {
            if (this.getY() < this.backY) {
                if (++count > 1) {
                    if (this.getFrame() == 4) {
//                        this.count =-1;
                        this.state = Character.JUM;
                        this.use_gravity = true;
                        this.count = 1;
                    } else {
                        this.nextFrame();
                        count = 0;
                    }

                }

            } // skill 2 when stand
            else {
                if (++count > 1) {
                    if (this.getFrame() == (skill1.length - 1)) {
//                        this.count =-1;
                        this.state = Character.IDLE;
                        this.count = -1;
                    } else {
                        this.nextFrame();
                        count = 0;
                    }
                }
            }
        }
    }

    public void skill2() {
//        Debug.d("Liu Kang skill 1");
        // skill 1 when jump
        if (count == -1) {
            this.setImage(Iskill2, 136, 128);
            this.setFrameSequence(skill2);
            if (left) {
                this.dx = 8;
            } else {
                this.dx = -8;
            }
            backX = this.getX();
            this.setPosition(this.getX() + dx, this.getY());
            count = 0;
        } else {
            if (this.getFrame() != (skill2.length - 1)) {
                this.nextFrame();
            }
            this.setPosition(this.getX() + dx, this.getY());
            if ((this.getX() - backX) > 150) {
                setVer(0, 0);
                this.setState(Character.IDLE);
            }
            if (collidesWith(this.rival, true)) {
                setVer(0, 0);
                // tru mau
                this.setState(Character.IDLE);
                this.rival.setState(Character.BEFALL2);
            }
        }
    }

    public void fatality() {
        if (count == -1) {
            this.setImage(chao1, 90, 128);
            this.setFrameSequence(fatality1);
            count = 0;
        } else if(count++ > 3){
            
            this.nextFrame();
            count =0;
            if (this.getFrame() == 12) {
                Debug.d("1");
                this.setImage(chao2, 90, 128);
                this.setFrameSequence(fatality1);
                this.setFrame(12);
            }
            if (this.getFrame() == 26) {
                Debug.d("2");
                this.setImage(bien, 90, 128);
                this.setFrameSequence(fatality1);
                this.setFrame(26);
            }
            if(this.getFrame() == 0){
                Debug.d("3");
                this.setState(Character.IDLE);
            }
        }
    }

    public void babality() {
    }

    public void wrestle() {
        if (count == -1) {
            this.setImage(Iwrestle, 90, 128);
            this.setFrameSequence(wrestle);
            count = 0;
        } else {
            this.nextFrame();
            if (this.getFrame() == 0) {
                this.setState(Character.IDLE);
            }
        }
    }

    public int getXL() {
        return this.getX();
    }
    //======================== Cac dong tac bi danh===============

    public void bePunch() {
        if (count == -1) {
            this.setImage(IbePunch, 64, 128);
            this.setFrameSequence(bePunch);
            if (lui) {
                this.backX = this.getX();
                if (left) {
                    this.setPosition(this.getX() + 14, this.getY());
                } else {
                    this.setPosition(this.getX() - 14, this.getY());
                }
                lui = false;
            }
            //mat mau
            count = 0;
        } else {
            if (this.getFrame() == (bePunch.length - 1)) {
                this.setState(Character.IDLE);
                if (!lui) {
                    Debug.d("Quay lai vi tri tai" + this.getFrame());
                    this.setPosition(backX, this.getY());
                    lui = true;
                }
            } else {
                this.nextFrame();
                Debug.d("Frame " + this.getFrame());
            }
        }
    }

    public void bePunch2() {
//        if (count == -1) {
//            this.setImage(IbePunch, 64, 128);
//            this.setFrameSequence(bePunch);
//            if (lui) {
//                this.backX = this.getX();
//                if (left) {
//                    this.setPosition(this.getX() + 14, this.getY());
//                } else {
//                    this.setPosition(this.getX() - 14, this.getY());
//                }
//                lui = false;
//            }
//            //mat mau
//            count = 0;
//        } else {
//            if (this.getFrame() == (bePunch.length - 1)) {
//                this.setState(Character.IDLE);
//                if (!lui) {
//                    Debug.d("Quay lai vi tri tai" + this.getFrame());
//                    this.setPosition(backX, this.getY());
//                    lui = true;
//                }
//            } else {
//                this.nextFrame();
//                Debug.d("Frame " + this.getFrame());
//            }
//        }
    }

    public void beFall1() {
        if (count == -1) {
            this.setImage(IbeFall, 90, 128);
            this.setFrameSequence(beFall);
            count = 0;
            if (left) {
                dx = -7;
            } else {
                dx = 7;
            }
        } else {
            if (this.getFrame() == (this.beFall.length - 1)) {
                this.setState(Character.IDLE);
                this.dx = 0;
            } else {
                this.nextFrame();
                if (this.getFrame() == 6) {
                    dx = 0;
                }
                this.setPosition(this.getX() + dx, this.getY());
            }
        }
    }

    public void beFall2() {
        if (count == -1) {
            this.setImage(IbeFall, 90, 128);
            this.setFrameSequence(beFall);
            count = 0;
            if (left) {
                dx = -7;
            } else {
                dx = 7;
            }
            this.dy = -15;
        } else {
            if (this.getFrame() == (this.beFall.length - 1)) {
                this.setState(Character.IDLE);
                this.dx = 0;
            } else {
                this.nextFrame();
                if (this.getFrame() == 6) {
                    dx = 0;
                }
                if (this.getY() + dy >= this.backY) {
                    this.dy = 0;
                    this.setPosition(this.getX() + dx, this.backY);
                } else {
                    this.setPosition(this.getX() + dx, this.getY() + dy);
                }
            }
        }
    }

    public void beWrestle() {
        if (count == -1) {
            setCharacterCheckSpace(false);
            this.setImage(IbeWrestle, 90, 128);
            this.setFrameSequence(beWrestle);
            count = 0;
            if (left) {
                dx = +10;
            } else {
                dx = -10;
            }
            this.dy = -17;
        } else {
            if (this.dy != 0) {
                this.setPosition(this.getX() + dx, this.getY() + dy);
                if (this.getY() > this.backY) {
                    dy = 0;
                }
            } else {
//                this.setPosition(this.getX() + dx, this.getY());
            }
            this.nextFrame();
            if (this.getFrame() == 0) {
                setCharacterCheckSpace(true);
                this.setState(Character.IDLE);
            }
        }
    }
    //============================================================

    private class LiuKangSkill extends Skill {

        private int d;
        private boolean hit = false;
        private boolean changePosition = true;

        public LiuKangSkill(int x, int y, int d) {
            super(ImainSkill, 90, 128);
            sk = new int[]{0, 0, 0, 1, 3, 4, 5, 11, 12, 13, 14, 15, 16, 17, 18};
            this.setFrameSequence(sk);
            this.setPosition(x + 50, y - 28);
            if (d < 0) {
                this.setTransform(Sprite.TRANS_MIRROR);
            }
            this.d = d;
        }

        public void update() {
            if (this.collidesWith(rival, true) && !hit) {
                hit = true;
                // - mau
                rival.setState(Character.BEPUNCH);
            }
            if (!hit) {
                if (this.getFrame() < 4) {
                    this.nextFrame();
                } else {
                    this.setPosition(this.getX() + d, this.getY());
                }
            } else {
                if (changePosition) {
                    this.setPosition(rival.getX() - 13, this.getY());
                    this.setFrame(5);
                    changePosition = false;
                }
                this.nextFrame();
                if (this.getFrame() == 14 || this.getFrame() == 0) {
                    gm.listSkill.removeElement(this);
                    return;
                }
            }
            if (Math.abs(this.getX() - getXL()) > 320) {
                gm.listSkill.removeElement(this);
            }
        }
    }
}
